<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/album/ListDir.class.php
 *
 * 查看用户特定目录的相片
 *
 * PHP Version 5
 *
 * @package:   class.album
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: $
 * @date:      $Date: $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';

//包含相册的工具表
include_once CLASS_PATH.'album/AlbumUtil.class.php';
include_once CLASS_PATH.'user/UserUtil.class.php';

class ListDir extends BaseAction {
   /**
    * 数据库的连接
    */
   private $db;

   /**
    * 每一页显示的相片的数量
    */
   private $pre_page = 40;


   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }


   /**
    * 显示用户的相册集里特定的目录
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function run() {
      //取得目录的id
      $dir = $this->getParameterFromGET('dir');
      $dir_name = AlbumUtil::getDirName($this->db, $dir);

      if ( !$dir ) {
         $this->AlertAndBack('请指定需要查看的目录');
         return;
      }

      if ( !AlbumUtil::isDirExists($this->db, $dir) ) {
         $this->AlertAndBack('需要查看的目录不存在');
         return;
      }

      //取得用户当前查看的目录
      $page = $this->getParameterFromGET('page');
      
      if ( !$page ) {
         $page = 1;
      }

      $total_page = AlbumUtil::getTotalPageByDir($this->db, $dir, $this->pre_page);
      
      if ( $page > $total_page && $total_page > 0 ) {
         $page = $total_page;
      }

      $option = "";
      for($i=1; $i<=$total_page; $i++ ) {
         $option .= "<option value=$i ";
         if ( $page == $i ) {
            $option .= " selected ";
         }
         $option .= ">第".$i."页\n";
      }


      $offset_page = ( $page - 1 ) * $this->pre_page;


      //取得用户的id
      $user_id = AlbumUtil::getUserIdByDir($this->db, $dir);


      //取得用户的昵称
      $album_user_name = UserUtil::getUserNameById($this->db, $user_id);

      //取得用户的相册目录

      $smarty = $this->getSmarty();
      $smarty->assign('page_option', $option);

      $smarty->assign('album_user_name', $album_user_name);
      $smarty->assign('user_id', $user_id);
      $smarty->assign('dir_id', $dir);
      $smarty->assign('dir_name', $dir_name);

      //取得该页面下的相片的资料
      $photo_info = AlbumUtil::getPhotoFromDirByPage($this->db, $dir, $this->pre_page, $offset_page);

      $smarty->assign('photo', $photo_info);



      //为了SEO
      $smarty->assign('clone_title', $album_user_name.'的相册->'.$dir_name.'/5anet.com' );
      $smarty->assign('header_meta_content', $album_user_name.'的相册->'.$dir_name.'/5anet.com' );


      $smarty->display('userdiralbum.tmpl');

 

   }
}






?>
